﻿using ImTools;
using Mododor.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace Mododor.Ext
{
    public static class QuickRefValueForMore<T> where T : class
    {
        /// <summary>
        /// 反射快速赋值
        /// </summary>
        /// <param name="value">需要赋值的对象</param>
        /// <param name="value1">数据对象</param>
        /// <returns></returns>
        public static T SetValueForMore(T value, T value1)
        {
            Type type = value.GetType();
            Type type1 = value1.GetType();
            PropertyInfo[] propinfos = type.GetProperties();
            PropertyInfo[] propinfo1 = type1.GetProperties();
            foreach (var item in propinfos)
            {
                var res = propinfo1.Single(x => x.Name == item.Name);
                res.SetValue(value, item.GetValue(value1));
            }
            return value;
        }
    }
}
